package class02;

/**
 * @author zhangchaoliang
 * create 2022
 */
public class DeleteGivenValue {
    public static class Node {
        public int value;
        public Node next;
        public Node(int data){
            value=data;
        }
    }

    public static Node removeValue(Node head,int num){
        while (head!=null){
            if (head.value!=num)
                break;
            head=head.next;
        }
        Node pre = head;
        Node cur = head;
        while (cur!=null){
            if (cur.value==num){
                pre.next=cur.next;
            }else {
                pre=cur;
            }
            cur=cur.next;
        }
        return head;
    }
}
